#ifndef DATATYPES_H_
#define DATATYPES_H_

#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned long

#define SIGNED_BYTE signed char
#define SIGNED_WORD signed short
#define SIGNED_DWORD signed long

#define BOOL BYTE

#ifndef TRUE
#define TRUE 1
#endif  


#ifndef FALSE
#define FALSE 0
#endif  

#ifndef YEP
#define YEP TRUE

#define ACTION_BEFORE_SERIAL_BYTE_ENQUEUE      ENABLE_TX_IRQ 

#endif  


#ifndef NOPE
#define NOPE FALSE
#endif  


#define STACK_FULL       -1
#define STACK_EMPTY      -2
#define STACK_PUSH_OK     0

#define QUEUE_FULL       -1
#define QUEUE_EMPTY      -2
#define QUEUE_OK	      0


typedef struct{

            BYTE *StackSpace;
            WORD Ptr;
            WORD Size;
}    ByteStack;

typedef struct{
            BYTE *StackSpace;
            BYTE Ptr;
            BYTE Size;
} BitStack;

typedef struct {
                
     	BYTE *BitPlaneSpace;

    	WORD SizeX; // must be a BYTE aligned
      WORD SizeY;
        
} BitPlane;




typedef struct {
	
	WORD ReadPtr;
	WORD WritePtr;
	WORD QueueSize;
	BYTE *QueueStorage;
	
} ByteQueue;



BOOL BitPlane_Get(BitPlane  * BP, WORD X,WORD Y);
void BitPlane_Put(BitPlane  * BP, WORD X,WORD Y, BOOL Value);

void BitPlane_Clear(BitPlane  * BP);

void InitByteQueue(ByteQueue *BQ,WORD Size,BYTE * Storage);
WORD BytesInQueue(ByteQueue *BQ);
SIGNED_WORD ByteDequeue(ByteQueue *BQ,BYTE *Val);
SIGNED_WORD ByteEnqueue(ByteQueue *BQ,BYTE Val);
SIGNED_WORD ByteArrayEnqueue(ByteQueue *BQ,BYTE *Buf,WORD Len);

SIGNED_WORD SerialByteArrayEnqueue(ByteQueue *BQ,BYTE *Buf,WORD Len);
SIGNED_WORD SerialByteEnqueue(ByteQueue *BQ,BYTE Val);


#define FIXED_7_8   SIGNED_WORD
#define MUL_FIXED_7_8_to_FIXED_7_8(A,B)   (FIXED_7_8)((((SIGNED_DWORD)(A))*((SIGNED_DWORD)(B)))>>8)

#define DIV_FIXED_7_8_by_FIXED_7_8(A,B)   (FIXED_7_8)((((SIGNED_DWORD)(A)<<8)/((SIGNED_DWORD)(B))))

#endif /*DATATYPES_H_*/
